package com.leagsoft.emm.demo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.huawei.secoclient.sslvpn.ConstValue;
import com.huawei.secoclient.sslvpn.VpnUtils;
import com.leagsoft.emm.demo.util.ToastUtil;

/**
 * 双因子验证页面
 */
public class SimWarningCheckActivity extends AppCompatActivity {
    private EditText etSimCheck;
    private Button btSubmit;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sms_warning);
        initView();
    }

    private void initView() {
        etSimCheck = (EditText) findViewById(R.id.et_sim);
        btSubmit = (Button) findViewById(R.id.btn_sim_submit);
        btSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String simcode = etSimCheck.getText().toString().trim();
                boolean success = VpnUtils.verificationCode(simcode, code -> {
                    if (code == ConstValue.LOGIN_SIM_SUCCESS) {
                        ToastUtil.show(SimWarningCheckActivity.this, "验证码登录成功 响应码:" + code);
                        finish();
                    } else if (code == ConstValue.LOGIN_SIM_CNEM_FAIL) {
                        ToastUtil.show(SimWarningCheckActivity.this, "验证码网络扩展失败 响应码:" + code);
                    } else {
                        ToastUtil.show(SimWarningCheckActivity.this, "验证码登录失败 响应码:" + code);
                    }
                });

                if (success) {
                    ToastUtil.show(SimWarningCheckActivity.this, "双因子登录构建成功 ");
                } else {
                    ToastUtil.show(SimWarningCheckActivity.this, "双因子登录构建失败 ");
                }
            }
        });
    }
}
